﻿using System;
using System.Collections.Generic;
using Algoritmia.DataStructures.PriorityQueues;
using Algoritmia.Utils;
using Lists = Algoritmia.DataStructures.Lists;

namespace Algoritmia.Problems.Sorting
{
    public class HeapSorter<T> : ISorter<T>
    {
        #region ISorter<T> Members

        public IEnumerable<T> Sorted(Lists.IList<T> list,Comparison<T> comparison = null)
        {
            var heap = new Heap<T>(list, comparison: AlgoritmiaFactory.GetDefaultComparison(comparison) );
            while ( heap.Count > 0 )
            {
                yield return heap.ExtractOptimal();
            }
        }

        #endregion
    }
}
